<template>
  <el-dialog :visible.sync="dialogVisible" width="800px" :before-close="handleClose" :close-on-click-modal="false"
    append-to-body :title="title">
    <el-form :model="form" ref="formRef" label-width="90px">
      <!--     <el-form-item
        label="用户名"
        prop="name"
        :rules="[{ required: true, message: '请输入用户名', trigger: 'blur' }]"
      >
        <el-input placeholder="请输入" disabled v-model="form.name"></el-input>
      </el-form-item> -->

      <!--  <el-form-item
        label="登录账号"
        prop="username"
        :rules="[
          { required: true, message: '请输入登录账号', trigger: 'blur' },
        ]"
      >
        <el-input placeholder="请输入" v-model="form.username"></el-input>
      </el-form-item> -->

      <!-- <el-form-item label="登录密码" prop="password" :rules="[{ required: true, message: '请输入登录密码', trigger: 'blur' }]">
        <el-input
          placeholder="请输入"
          v-model="form.password"
        ></el-input>
      </el-form-item> -->
      <el-form-item label="申请项目" prop="skillData">
        <div style="margin-left: 20px" v-for="o in this.form.skillData" :key="o">
          <ul>
            <li style="list-style-type: disc">
              <span style="font-weight: bold; font-size: 20px">{{ o }}</span>
            </li>
          </ul>
        </div>
      </el-form-item>

      <el-form-item label="审核备注" prop="remark" :rules="[
          { required: true, message: '请输入审核备注', trigger: 'blur' },
        ]">
        <el-input resize="none" type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" placeholder="请输入"
          v-model="form.remark"></el-input>
      </el-form-item>
      <!--  <el-form-item
        label="职称"
        prop="position"
        :rules="[{ required: true, message: '请输入职称', trigger: 'blur' }]"
      >
        <el-input placeholder="请输入" v-model="form.position"></el-input>
      </el-form-item>
 -->
      <!--   <el-form-item
        label="所属科室"
        prop="department_id"
        :rules="[
          { required: true, message: '请选择所属科室', trigger: 'change' },
        ]"
      >
        <el-select
          v-model="form.department_id"
          clearable
          filterable
          placeholder="请选择"
        >
          <el-option
            v-for="item in departmentData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
 -->
      <!--    <el-form-item
        label="所属角色"
        prop="role_id"
        :rules="[
          { required: true, message: '请选择所属角色', trigger: 'change' },
        ]"
      >
        <el-select
          v-model="form.role_id"
          clearable
          filterable
          placeholder="请选择"
        >
          <el-option
            v-for="item in roleData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item> -->
      <!--  <el-form-item
        label="所属机构"
        prop="unit"
        :rules="[
          { required: true, message: '请输入所属机构', trigger: 'blur' },
        ]"
      >
        <el-input placeholder="请输入" v-model="form.unit"></el-input>
      </el-form-item> -->
    </el-form>
    <div slot="footer" class="tx-c">
      <el-button style="width: 200px" type="danger" @click="confirm('不通过')">不通过</el-button>
      <el-button type="primary" style="width: 200px" @click="confirm('通过')" :loading="btnLoading">通过</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { debounce } from "@/util";
import {
  ApiDoctorEdit,
  ApiQualificationApplyHandle,
  ApiskillApply,
} from "@/api/index.js";
import ImgUploadPath from "@/components/imgUpload-path.vue";
import { validatePhone } from "@/util/validate";
export default {
  props: ["roleData", "departmentData"],
  components: {
    ImgUploadPath,
  },
  data() {
    return {
      validatePhone,
      optionsData: [
        { name: "男", code: "男" },
        { name: "女", code: "女" },
      ],
      levelArr: [
        { name: "普通", code: "普通" },
        { name: "中级", code: "中级" },
        { name: "高级", code: "高级" },
      ],

      oldform: {
        name: "",
        skill: "",
        level: "",
        file: "",
        remark: "",
        skillData: [],
        password: "",
        /*    unit: "京山市人民医院", */
      },
      form: {},
      btnLoading: false,
      dialogVisible: false,
      id: null,
      title: "",
      imgsDefalut: [],
    };
  },

  methods: {
    onUploadSuccess(path) {
      console.log("111", path);
      this.form.icon = path;
    },
    onUploadRemove() {
      this.form.icon = "";
    },
    confirm: debounce(
      function (val) {
        this.$refs["formRef"].validate(async (valid) => {
          if (valid) {
            this.btnLoading = true;
            try {
              await ApiQualificationApplyHandle(this.id, {
                ...this.form,
                status: val,
              });
              this.$message.success("修改成功");
              this.handleClose();
              this.$emit("refresh");
            } finally {
              this.btnLoading = false;
            }
          } else return false;
        });
      },
      500,
      true
    ),

    show(row) {
      console.log("111111", row);
      const data = row || this.oldform;
      for (const key in this.oldform) {
        this.$set(this.form, key, data[key]);
      }
      if (row) {
        this.id = row.id;
        this.title = "审核数据";
        /*      if (row.file) {
          this.imgsDefalut = row.file.split(",");
        } */
        this.getSkillApplyArr();

        /*    this.imgsDefalut = [{ url: this.$path + row.file }]; */
      } else {
        this.id = null;
        this.title = "添加人员";
      }
      this.dialogVisible = true;
    },

    getSkillApplyArr() {
      ApiskillApply(this.id).then((res) => {
        console.log(res);
        this.form.skillData = res.data;
      });
    },

    handleClose() {
      this.dialogVisible = false;
      this.form = { ...this.oldform };
      this.$nextTick((_) => {
        this.$refs.formRef.clearValidate();
        /*   this.$refs.ImgUploadPath.clear(); */
      });
    },
  },
};
</script>

<style></style>
